package com.sline.Test;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.net.ServerSocket;
import java.net.Socket;

public class Demo1_Server {
    public static void main(String[] args) throws IOException {

        ServerSocket server = new ServerSocket(12345);

        while (true) {

            Socket socket = server.accept();

            new Thread() {
                public void run() {
                    while (true) {
                        try {
                            BufferedReader br = new BufferedReader(new InputStreamReader(socket.getInputStream()));
                            PrintStream ps = new PrintStream(socket.getOutputStream());

                            String msg = br.readLine();

                            System.out.println("服务器收到请求内容: " + msg);

                            StringBuilder sb = new StringBuilder(msg);
                            sb.reverse();
                            String newStr = sb.toString();

                            ps.println(newStr);
                        } catch (IOException e) {
                            e.printStackTrace();
                        }
                    }
                }
            }.start();
        }
    }
}
